feat: Support staged re-invocation of agents (bidirectional workflows)#68
Draft
aviraldua93 wants to merge 2 commits intomicrosoft:mainfrom
Draft
feat: Support staged re-invocation of agents (bidirectional workflows)#68aviraldua93 wants to merge 2 commits intomicrosoft:mainfrom
aviraldua93 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Implements GitHub issue microsoft#65 — allows the same agent to appear at multiple stages in a workflow with different prompts, inputs, and outputs while sharing model, tools, and system prompt configuration. ## Design Agents can now declare a stages dict with named invocation points: `yaml agents: - name: vp_engineering model: gpt-4.1 prompt: 'Set technical direction...' stages: review: prompt: 'Review your team''s output...' input: [ic.output] ` Stages are expanded into synthetic AgentDef instances at config load time (e.g., �p_engineering:default, �p_engineering:review), so the workflow engine sees regular agents and requires minimal changes. ## Changes **Schema & Config** (src/conductor/config/): - New StageDef Pydantic model with optional overrides (prompt, input, output, routes, description) - AgentDef.stages: dict[str, StageDef] | None field - �xpander.py — stage expansion with name collision detection, route rewriting, and entry point rewriting - Validator updated for stage-qualified input refs, for-each inline agent stages rejection, and parallel group stages rejection **Engine** (src/conductor/engine/context.py): - Dual-key storage: stage-qualified outputs stored under both �gent:stage and �gent (latest) keys for backward compatibility - _build_stages_dict() for Jinja2 access via stages.agent.stage.output - Stages dict injected into all three context modes **Tests** (42 new tests): - est_expander.py — 34 tests covering StageDef schema, expansion, edge cases, name collisions, for-each validation - est_staged_workflow.py — 8 integration tests covering VP→IC→VP:review execution, loop-back, backward compatibility, context storage **Example**: �xamples/staged-review.yaml — VP→IC→VP:review pattern Closes microsoft#65 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- 20 assertions: node rendering, detail panels, API state, token counts - Screenshots: completed, in-progress, each node detail, mobile, dark mode - Tests: stage-qualified agents visible, API returns correct events Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements staged re-invocation of agents (#65) — allowing the same agent to appear at multiple stages in a workflow with different prompts, inputs, and outputs while sharing model, tools, and system prompt configuration.
Problem
In real company workflows, the same role both directs work (going down) and reviews results (coming back up). Currently this requires duplicate agent nodes with duplicated config.
Solution
A new optional
stagesdict onAgentDef:`yaml
agents:
model: gpt-4.1
system_prompt: "You are VP Engineering..."
prompt: "Set technical direction..."
stages:
review:
prompt: "Review your team's output..."
input: [ic.output]
routes:
- to: ic
when: "verdict == 'revise'"
- to: $end
`
Stages expand into synthetic
AgentDefinstances at config load time (vp:default,vp:review), so the engine requires zero changes toworkflow.pyandrouter.py.Changes
schema.py,expander.py(new)StageDefmodel,AgentDef.stagesfield, expansion logic with name collision detectionvalidator.pycontext.pyagent:stage+agentlatest),stagesdict for Jinja2test_expander.py,test_staged_workflow.pystaged-review.yamltake_screenshots.pyDesign Decisions
agent:stage) — avoids collision with dot-path output references{{ vp.output }}returns latest output from any stage,{{ stages.vp.review.output }}accesses specific stagestagesdefaults toNone; existing workflows unchangedScreenshots
Completed Staged Workflow
Node Detail (vp:review)
In-Progress
Dark Mode
Mobile
Test Results
make validate-examplespassesCloses #65